package br.com.salao.model;

import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;

import org.apache.log4j.Logger;

import br.com.salao.entity.DiaSemana;
import br.com.salao.session.DiaSemanaBase;
import br.com.salao.util.Utils;

public class DiaSemanaModel {
	
	/**
	 * @author Adriana Del Nero  
	 */

	private Logger logger =  Logger.getLogger(CidadeModel.class.getName());

	public DiaSemana incluir(DiaSemana diaSemana){
		try{
			DiaSemanaBase diaSemanaBase  = getBean();
			return diaSemanaBase.incluir(diaSemana);
		} catch (Exception e) {

			StringBuffer sb = new StringBuffer();
			sb.append(e.getStackTrace());
			logger.debug(sb.toString());

			return null;
		}
	}

	public DiaSemana update(DiaSemana diaSemana){
		try{
			DiaSemanaBase diaSemanaBase  = getBean();
			return diaSemanaBase.update(diaSemana);
		} catch (Exception e) {

			StringBuffer sb = new StringBuffer();
			sb.append(e.getStackTrace());
			logger.debug(sb.toString());

			return null;
		}
	}

	public DiaSemana buscarDiaSemanaPorIdEstabelecimentos(int idEstabelecimento){
		try{
			DiaSemanaBase diaSemanaBase  = getBean();
			return diaSemanaBase.buscarDiaSemanaPorIdEstabelecimentos(idEstabelecimento);
		} catch (Exception e) {

			StringBuffer sb = new StringBuffer();
			sb.append(e.getStackTrace());
			logger.debug(sb.toString());

			return null;
		}
	}
    public DiaSemanaBase getBean() throws Exception {
    	
        Properties prop = Utils.getProperties();     
        Context ctx = new InitialContext(prop); 
        Object ref = ctx.lookup(prop.getProperty("DIASEMANA_LOOKUP"));       
      
        return (DiaSemanaBase)PortableRemoteObject.narrow(ref, DiaSemanaBase.class);
    }
}
